using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace KeyAuthService.Dialogs
{
    /// <summary>
    /// 现代风格确认对话框
    /// </summary>
    public class ModernConfirmDialog : Window
    {
        public bool IsConfirmed { get; private set; } = false;
        
        public ModernConfirmDialog(string message, string title, string confirmText = "确定", string cancelText = "取消", bool isWarning = false)
        {
            Title = title;
            Style = (Style)FindResource("DialogWindowStyle");
            MinWidth = 420;
            MinHeight = 180;
            WindowStartupLocation = WindowStartupLocation.CenterScreen;
            Topmost = true;
            SizeToContent = SizeToContent.WidthAndHeight;
            ResizeMode = ResizeMode.NoResize;
            
            // 创建主容器
            var grid = new Grid();
            grid.Style = (Style)FindResource("DialogContainerStyle");
            
            grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) });
            grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) });
            
            // 内容容器
            var contentPanel = new StackPanel
            {
                Margin = new Thickness(0, 0, 0, 20)
            };
            
            // 如果是警告样式，添加警告图标
            if (isWarning)
            {
                var warningPanel = new StackPanel
                {
                    Orientation = Orientation.Horizontal,
                    Margin = new Thickness(0, 0, 0, 15)
                };
                
                var warningIcon = new TextBlock
                {
                    Text = "⚠️",
                    FontSize = 24,
                    Margin = new Thickness(0, 0, 10, 0),
                    VerticalAlignment = VerticalAlignment.Center
                };
                
                var warningTitle = new TextBlock
                {
                    Text = "请确认此操作",
                    FontSize = 16,
                    FontWeight = FontWeights.SemiBold,
                    VerticalAlignment = VerticalAlignment.Center
                };
                
                warningPanel.Children.Add(warningIcon);
                warningPanel.Children.Add(warningTitle);
                
                contentPanel.Children.Add(warningPanel);
            }
            
            // 消息文本
            var messageText = new TextBlock
            {
                Text = message,
                TextWrapping = TextWrapping.Wrap,
                Style = (Style)FindResource("DialogPromptStyle")
            };
            
            contentPanel.Children.Add(messageText);
            
            // 按钮面板
            var buttonPanel = new StackPanel
            {
                Style = (Style)FindResource("DialogButtonPanelStyle")
            };
            
            // 取消按钮
            var btnCancel = new Button
            {
                Content = cancelText,
                Style = (Style)FindResource("DialogSecondaryButtonStyle"),
                IsCancel = true
            };
            
            // 确认按钮
            var btnConfirm = new Button
            {
                Content = confirmText,
                IsDefault = true
            };
            
            // 根据是否为警告设置确认按钮样式
            if (isWarning)
            {
                btnConfirm.Style = (Style)Application.Current.Resources["DialogDangerButtonStyle"];
            }
            else
            {
                btnConfirm.Style = (Style)Application.Current.Resources["DialogPrimaryButtonStyle"];
            }
            
            btnConfirm.Click += (s, e) => 
            {
                IsConfirmed = true;
                DialogResult = true;
            };
            
            // 添加按钮到面板
            buttonPanel.Children.Add(btnCancel);
            buttonPanel.Children.Add(btnConfirm);
            
            // 添加控件到布局
            grid.Children.Add(contentPanel);
            Grid.SetRow(contentPanel, 0);
            
            grid.Children.Add(buttonPanel);
            Grid.SetRow(buttonPanel, 1);
            
            Content = grid;
        }
    }
} 